package com.hd.trans.db.bean;

import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.hd.trans.db.greenDao.DaoSession;
import com.hd.trans.db.greenDao.HuDunLanguageDao;
import com.hd.trans.db.greenDao.TranslateRecordDao;
import com.hd.trans.homefun.RecordType;

import org.greenrobot.greendao.DaoException;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Property;
import org.greenrobot.greendao.annotation.ToOne;
import org.greenrobot.greendao.annotation.Transient;

/**
 * Author:  yang
 * Date:    2020/01/07 9:00
 * Desc:    翻译记录
 */
@Entity
public class TranslateRecord implements MultiItemEntity {

    @Id(autoincrement = true)
    private Long id;


    @Property(nameInDb = "is_voice")
    private boolean isVoice;//是否为语音页

    private Long languageFromId;//这是与语言关联的外键

    @ToOne(joinProperty = "languageFromId") //这个是注解绑定 languageFromId
    private HuDunLanguage languageFrom;//对象--关联语言

    private Long languageToId;//这是与语言关联的外键

    @ToOne(joinProperty = "languageToId") //这个是注解绑定 languageToId
    private HuDunLanguage languageTo;//对象--关联语言


    @Property(nameInDb = "trigger_time")
    private long triggerTime = 0; //触发时间


    @Property(nameInDb = "content_orig")
    private String contentOrig;//原内容


    @Property(nameInDb = "pinyin_org")
    private String pinyinOrig;//原文拼音

    @Property(nameInDb = "content_translate")
    private String contentTranslate;//译文内容

    @Property(nameInDb = "pinyin_translate")
    private String pinyinTranslate;//译文拼音

    @Property(nameInDb = "is_collected")
    private boolean isCollected;//是否被收藏


    @Property(nameInDb = "is_reverse")
    private boolean isReverse;//是否为逆向翻译(从右到左)

    /**
     * @see com.hd.trans.common.Constants.VoiceRecordState
     */
    @Property(nameInDb = "record_state")
    private int translateState;//翻译状态

    @Property(nameInDb = "is_nation")
    private boolean isNation;//是否为民族语言


    @Property(nameInDb = "record_type")
    private int recordType = RecordType.TEXT;//记录类型

    @Property(nameInDb = "voice_file")
    private String voiceFile;//语音文件路径

    @Transient
    private transient boolean isSelect;//是否选中



    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public boolean getIsVoice() {
        return this.isVoice;
    }

    public void setIsVoice(boolean isVoice) {
        this.isVoice = isVoice;
    }

    public Long getLanguageFromId() {
        return this.languageFromId;
    }

    public void setLanguageFromId(Long languageFromId) {
        this.languageFromId = languageFromId;
    }

    public Long getLanguageToId() {
        return this.languageToId;
    }

    public void setLanguageToId(Long languageToId) {
        this.languageToId = languageToId;
    }

    public long getTriggerTime() {
        return this.triggerTime;
    }

    public void setTriggerTime(long triggerTime) {
        this.triggerTime = triggerTime;
    }

    public String getContentOrig() {
        return this.contentOrig;
    }

    public void setContentOrig(String contentOrig) {
        this.contentOrig = contentOrig;
    }

    public String getContentTranslate() {
        return this.contentTranslate;
    }

    public void setContentTranslate(String contentTranslate) {
        this.contentTranslate = contentTranslate;
    }

    public boolean getIsCollected() {
        return this.isCollected;
    }

    public void setIsCollected(boolean isCollected) {
        this.isCollected = isCollected;
    }

    public boolean getIsReverse() {
        return this.isReverse;
    }

    public void setIsReverse(boolean isReverse) {
        this.isReverse = isReverse;
    }

    public int getTranslateState() {
        return this.translateState;
    }

    public void setTranslateState(int translateState) {
        this.translateState = translateState;
    }

    @Generated(hash = 1487464742)
    private transient Long languageFrom__resolvedKey;


    /** Used to resolve relations */
    @Generated(hash = 2040040024)
    private transient DaoSession daoSession;


    /** Used for active entity operations. */
    @Generated(hash = 265931971)
    private transient TranslateRecordDao myDao;



    @Generated(hash = 840195791)
    public TranslateRecord(Long id, boolean isVoice, Long languageFromId, Long languageToId,
            long triggerTime, String contentOrig, String pinyinOrig, String contentTranslate,
            String pinyinTranslate, boolean isCollected, boolean isReverse,
            int translateState, boolean isNation, int recordType, String voiceFile) {
        this.id = id;
        this.isVoice = isVoice;
        this.languageFromId = languageFromId;
        this.languageToId = languageToId;
        this.triggerTime = triggerTime;
        this.contentOrig = contentOrig;
        this.pinyinOrig = pinyinOrig;
        this.contentTranslate = contentTranslate;
        this.pinyinTranslate = pinyinTranslate;
        this.isCollected = isCollected;
        this.isReverse = isReverse;
        this.translateState = translateState;
        this.isNation = isNation;
        this.recordType = recordType;
        this.voiceFile = voiceFile;
    }

    @Generated(hash = 1523083295)
    public TranslateRecord() {
    }

    @Generated(hash = 1217978079)
    private transient Long languageTo__resolvedKey;


    @Override
    public String toString() {
        return "TranslateRecord{" +
                "id=" + id +
                ", isVoice=" + isVoice +
                ", languageFromId=" + languageFromId +
                ", languageFrom=" + languageFrom +
                ", languageToId=" + languageToId +
                ", languageTo=" + languageTo +
                ", triggerTime=" + triggerTime +
                ", contentOrig='" + contentOrig + '\'' +
                ", contentTranslate='" + contentTranslate + '\'' +
                ", isCollected=" + isCollected +
                ", isReverse=" + isReverse +
                ", translateState=" + translateState +
                ", isSelect=" + isSelect +
                ", daoSession=" + daoSession +
                ", myDao=" + myDao +
                ", languageFrom__resolvedKey=" + languageFrom__resolvedKey +
                ", languageTo__resolvedKey=" + languageTo__resolvedKey +
                '}';
    }


    @Override
    public int getItemType() {
        return  isReverse ? 1 : 0;
    }

    /** To-one relationship, resolved on first access. */
    @Generated(hash = 1818423403)
    public HuDunLanguage getLanguageFrom() {
        Long __key = this.languageFromId;
        if (languageFrom__resolvedKey == null
                || !languageFrom__resolvedKey.equals(__key)) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            HuDunLanguageDao targetDao = daoSession.getHuDunLanguageDao();
            HuDunLanguage languageFromNew = targetDao.load(__key);
            synchronized (this) {
                languageFrom = languageFromNew;
                languageFrom__resolvedKey = __key;
            }
        }
        return languageFrom;
    }

    /** called by internal mechanisms, do not call yourself. */
    @Generated(hash = 484036549)
    public void setLanguageFrom(HuDunLanguage languageFrom) {
        synchronized (this) {
            this.languageFrom = languageFrom;
            languageFromId = languageFrom == null ? null : languageFrom.getId();
            languageFrom__resolvedKey = languageFromId;
        }
    }

    /** To-one relationship, resolved on first access. */
    @Generated(hash = 1938515764)
    public HuDunLanguage getLanguageTo() {
        Long __key = this.languageToId;
        if (languageTo__resolvedKey == null
                || !languageTo__resolvedKey.equals(__key)) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            HuDunLanguageDao targetDao = daoSession.getHuDunLanguageDao();
            HuDunLanguage languageToNew = targetDao.load(__key);
            synchronized (this) {
                languageTo = languageToNew;
                languageTo__resolvedKey = __key;
            }
        }
        return languageTo;
    }

    /** called by internal mechanisms, do not call yourself. */
    @Generated(hash = 1780744424)
    public void setLanguageTo(HuDunLanguage languageTo) {
        synchronized (this) {
            this.languageTo = languageTo;
            languageToId = languageTo == null ? null : languageTo.getId();
            languageTo__resolvedKey = languageToId;
        }
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 128553479)
    public void delete() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.delete(this);
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#refresh(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 1942392019)
    public void refresh() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.refresh(this);
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#update(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 713229351)
    public void update() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.update(this);
    }

    /** called by internal mechanisms, do not call yourself. */
    @Generated(hash = 389697320)
    public void __setDaoSession(DaoSession daoSession) {
        this.daoSession = daoSession;
        myDao = daoSession != null ? daoSession.getTranslateRecordDao() : null;
    }

    public boolean getIsNation() {
        return this.isNation;
    }

    public void setIsNation(boolean isNation) {
        this.isNation = isNation;
    }

    public String getPinyinOrig() {
        return this.pinyinOrig;
    }

    public void setPinyinOrig(String pinyinOrig) {
        this.pinyinOrig = pinyinOrig;
    }

    public String getPinyinTranslate() {
        return this.pinyinTranslate;
    }

    public void setPinyinTranslate(String pinyinTranslate) {
        this.pinyinTranslate = pinyinTranslate;
    }

    public int getRecordType() {
        return this.recordType;
    }

    public void setRecordType(int recordType) {
        this.recordType = recordType;
    }

    public String getVoiceFile() {
        return this.voiceFile;
    }

    public void setVoiceFile(String voiceFile) {
        this.voiceFile = voiceFile;
    }
}